package com.hans.scala

import scala.reflect.runtime.{ universe => ru }
import scala.collection._

object ReflectRuntimeExample {
  def main(args: Array[String]) {
    val l = List(1, 2, 3)
    val theType = getTypeTag(l).tpe
    println(theType)
    val decls = theType.declarations.take(10)
    println(decls)
    println(theType.declarations.take(8))

    class E {
      type T
      val x: Option[T] = None
    }
    class C extends E
    class D extends C
    val c = new C { type T = String }
    val d = new D { type T = String }
    println(c.getClass.isAssignableFrom(d.getClass))
    def m[T: ru.TypeTag, S: ru.TypeTag](x: T, y: S): Boolean = {
      val leftTag = ru.typeTag[T]
      val rightTag = ru.typeTag[S]
      leftTag.tpe <:< rightTag.tpe
    }
    //    println(m(d, c))
  }

  def getTypeTag[T: ru.TypeTag](obj: T) = ru.typeTag[T]
}